import React, { Component } from 'react';
import { toJS } from 'mobx';
import { inject, observer } from 'mobx-react';
import { withRouter } from 'react-router-dom';
import { Modal, Tools } from 'weaver-mobile';
import { ListViewPage } from 'weaver-mobile-page';
import { getTemplateBasicItem, getTemplateLinkItem, getTemplateBasicItemToHtml, renderNoData } from '../public';
import BackTop from '../../public/back-to-top';
const getLabel = Tools.getLabel;
const alert = Modal.alert;

@withRouter
@inject('applyStore')
@observer
export default class QuitedCowork extends Component {

  static defaultProps = {
    prefixCls: 'cowork-apply-quited',
  }
  
  componentWillMount () {
    const { applyStore: { quitedCoworkStore } } = this.props;
    quitedCoworkStore.getCoworkApplyPageList();
  }

  getTemplate = () => {
    const newTemp = {
      default: [{
        key: 'col_1',
        render: (data) => {
          const curCls = "cowork-template-list";
          const applySpan = data.isapply !== '1' ? getLabel('513486','该协作不可申请加入') : data.isapplyspan;
          return (
            <div className={curCls} key={data.id}>
              {getTemplateBasicItem(curCls, getLabel(344, '主题'), data.namespan)}
              {getTemplateBasicItem(curCls, getLabel(83209, '版块'), data.typeidspan)}
              {getTemplateLinkItem(curCls, getLabel(2097, '负责人'), data.principalspan,data.principal)}
              {getTemplateBasicItemToHtml(curCls, getLabel(25734, '说明'), data.remarkspan)}
              {getTemplateBasicItem(curCls, getLabel('513106','退出时间'), data.quittimespan)}
              {getTemplateBasicItem(curCls, getLabel(83214,"申请加入"), applySpan)}
            </div>
          );
        },
      }],
    };
    return newTemp;
  }

  render() {
    const { prefixCls, applyStore: { quitedCoworkStore } } = this.props;
    const { quitedList, coworkApplayInfo } = quitedCoworkStore;
    const datas = toJS(quitedList.data);
    return datas.length === 0 ? renderNoData : (
      <div className={prefixCls}>
        <div className={`cowork-template`}>
          <BackTop
            visibilityHeight='200'
            modal
            target='wm-list-view-page-modal-scrollview'
          >
            <ListViewPage.Normal
              store={quitedList}
              getTemplate={this.getTemplate}
              onRowClick={(selectedRowKeys) => {
                if (selectedRowKeys.isapply === '1'  && (selectedRowKeys.statusspan === ""||selectedRowKeys.statusspan === "0")) {
                  let title = `${getLabel(390659, '确定要参加到')}【${selectedRowKeys.name}】${getLabel(386724, '吗')}？`;
                  let currentModel = alert(title,'', [
                    { text: getLabel(31129, '取消') },
                    {
                      text: getLabel(33703, '确认'),
                      onPress: () => {
                        coworkApplayInfo({coworkIds:selectedRowKeys.coworkid});                    
                      }
                    },
                  ]);
                }
                // setStoreState({ currentModel: currentModel });
              }}
            />
          </BackTop>
        </div>
      </div>
    )
  }
}
